package com.itheima.inetaddress;

import java.io.*;
import java.net.Socket;
import java.util.Arrays;

public class Demo10 {
    public static void main(String[] args) throws IOException {
        //创建客户端
        Socket socket = new Socket("127.0.0.1", 10000);
        //创建本地流,用于读数据
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("test-inetaddress\\client\\1.png"));
        //创建网络中的流,用于写数据
        OutputStream os = socket.getOutputStream();
        //包装一下
        BufferedOutputStream bos = new BufferedOutputStream(os);

        //将本地的数据写到网络中
        int len;
        while ((len = bis.read()) != -1) {
            bos.write(len);
        }
        bos.flush();
        //结束标记
        socket.shutdownOutput();


        //接收数据,用于读数据
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while((line = br.readLine()) !=null){
            System.out.println(line);
        }

        //关流
        socket.close();
        bis.close();

    }
}











